<?php
use Monolog\Handler\Curl\Util;

include 'protected/components/Youtube.php';
include 'protected/components/Utils.php';
class DataController extends Controller {
	/**
	 * http://localhost/topnews/topnews/NewsData.html?type=1&lid=3&cid=3&page=1
	 * http://localhost/topnews/topnews/index.php?r=index/index&type=1&lid=3&cid=3
	 */
	function actionNewsData() {
		// http://localhost/mangahi/index.php?r=manga/manga&curPage=&cid=$cid&mid=$mid
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => '' 
		);
		
		$lid = @$_GET ['lid'];
		$type = @$_GET ['type'];
		$cid = @$_GET ['cid'];
		$page = @$_GET ['page'];
		$pageSize = @$_GET ['pageSize'];
		$bd_board = bd_board::model ();
		$boardList = $bd_board->getBoardListByCid ( $lid, $cid, $type, $page );
		
		$arr = Array ();
		foreach ( $boardList as $mangaInfosBean ) {
			$model = Array (
					'id' => $boardList->id,
					'picture' => $boardList->picture,
					'width' => $boardList->width,
					'height' => $boardList->height,
					'name' => $boardList->name,
					'description' => $boardList->description,
					'pics' => $boardList->pics,
					'cid' => $boardList->cid,
					'focusNum' => $boardList->focusNum,
					'picNum' => $boardList->picNum 
			);
			array_push ( $arr, $model );
		}
		$result ['data'] = $arr;
		
		echo json_encode ( $result );
		// var_dump($boardList);
	}
	function actionSubCategoryData() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => '' 
		);
		
		$lid = @$_GET ['lid'];
		$categoryListModel = categorylist::model ();
		$menuList = $categoryListModel->getSubCategoryList ( $lid );
		
		$arr = Array ();
		foreach ( $menuList as $menuItem ) {
			$model = Array (
					'cid' => $menuItem->cid,
					'title' => $menuItem->title 
			);
			array_push ( $arr, $model );
		}
		$result ['data'] = $arr;
		
		echo json_encode ( $result );
		// var_dump($boardList);
	}
	
	// SearchVideo
	/**
	 * http://74.91.31.234/topnews/topnews/SearchVideo.html?keywords=manga&regionCode=&orderby=1&searchType=0
	 */
	function actionSearchVideo() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => '' 
		);
		
		$regionCode = @$_GET ['regionCode'];
		$searchType = @$_GET ['searchType'];
		$orderby = @$_GET ['orderby'];
		$keywords = @$_GET ['keywords'];
		$pageToken = @$_GET ['pageToken'];
		// if (empty($name)) return;
		$arr = Youtube::getInstance ()->searchVideos ( $regionCode, $orderby, $searchType, $keywords, $pageToken, 20 );
		
// 		Youtube::getInstance ()->getContentDetail ('9bZkp7q19f0');
		
		$result ['data'] = $arr;
		
		echo json_encode ( $result );
		// var_dump($boardList);
	}
	
	// SearchVideo
	/**
	 * http://74.91.31.234/topnews/topnews/SearchVideoByCid.html?cid=1&regionCode=&orderby=1&searchType=0
	 */
	function actionSearchVideoByCid() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => ''
		);
	
		$regionCode = @$_GET ['regionCode'];
		$searchType = @$_GET ['searchType'];
		$orderby = @$_GET ['orderby'];
		$cid = @$_GET ['cid'];
		$pageToken = @$_GET ['pageToken'];
		// if (empty($name)) return;
		$arr = Youtube::getInstance ()->searchVideosByCId ( $cid, $regionCode, $orderby, $searchType,$pageToken, 20 );
	
		// 		Youtube::getInstance ()->getContentDetail ('9bZkp7q19f0');
	
		$result ['data'] = $arr;
	
		echo json_encode ( $result );
		// var_dump($boardList);
	}
	
	// SearchVideo
	/**
	 * http://74.91.31.234/topnews/topnews/SearchVideosByRelateVID.html?cid=1&regionCode=&orderby=1&searchType=0
	 */
	function actionSearchVideosByRelateVID() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => ''
		);
	
		$regionCode = @$_GET ['regionCode'];
		$searchType = @$_GET ['searchType'];
		$orderby = @$_GET ['orderby'];
		$vid = @$_GET ['vid'];
		$pageToken = @$_GET ['pageToken'];
		// if (empty($name)) return;
		$arr = Youtube::getInstance ()->searchVideosByRelateVID ( $vid, $regionCode, $orderby, $searchType,$pageToken, 20 );
	
		// 		Youtube::getInstance ()->getContentDetail ('9bZkp7q19f0');
	
		$result ['data'] = $arr;
	
		echo json_encode ( $result );
		// var_dump($boardList);
	}
	
	/**
	 * http://74.91.31.234/topnews/topnews/SearchPlayList.html?keywords=manga&regionCode=&orderby=1&searchType=0
	 */
	function actionSearchPlayList() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => ''
		);
	
		$regionCode = @$_GET ['regionCode'];
		$searchType = @$_GET ['searchType'];
		$orderby = @$_GET ['orderby'];
		$keywords = @$_GET ['keywords'];
		$pageToken = @$_GET ['pageToken'];
		// if (empty($name)) return;
		$arr = Youtube::getInstance ()->searchPlayList ( $regionCode, $orderby, $keywords, $pageToken, 20 );
	
		// 		Youtube::getInstance ()->getContentDetail ('9bZkp7q19f0');
	
		$result ['data'] = $arr;
	
		echo json_encode ( $result );
		// var_dump($boardList);
	}

	/**
	 * http://74.91.31.234/topnews/topnews/SearchChannel.html?keywords=manga&regionCode=&orderby=1&searchType=0
	 */
	function actionSearchChannel() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => ''
		);
	
		$regionCode = @$_GET ['regionCode'];
		$searchType = @$_GET ['searchType'];
		$orderby = @$_GET ['orderby'];
		$keywords = @$_GET ['keywords'];
		$pageToken = @$_GET ['pageToken'];
		// if (empty($name)) return;
		$arr = Youtube::getInstance ()->searchChannel ( $regionCode, $orderby, $keywords, $pageToken, 20 );
	
		// 		Youtube::getInstance ()->getContentDetail ('9bZkp7q19f0');
	
		$result ['data'] = $arr;
	
		echo json_encode ( $result );
		// var_dump($boardList);
	}
	
	/**
	 * http://74.91.31.234/topnews/topnews/GetContentDetail.html?vid=9bZkp7q19f0
	 * 
	 */
	function actionGetContentDetail() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => ''
		);
		$videoID = $_GET['vid'];
		$arr = Youtube::getInstance ()->getContentDetail ($videoID);
		$result ['data'] = $arr;
		echo json_encode($result);
	}

	
	/**
	 * http://74.91.31.234/topnews/topnews/GetCommentsThread.html?vid=9bZkp7q19f0
	 *
	 */
	function actionGetCommentsThread() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => ''
		);
		$videoID = $_GET['vid'];
		$arr = Youtube::getInstance ()->getCommentsThread ($videoID, "");
		$result ['data'] = $arr;
		echo json_encode($result);
	}
	
	/**
	 * http://74.91.31.234/topnews/topnews/GetChannel.html?cid=9bZkp7q19f0
	 *
	 */
	function actionGetChannel() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => ''
		);
		$channelId = $_GET['cid'];
		$arr = Youtube::getInstance ()->getChannels ($channelId, "");
		$result ['data'] = $arr;
		echo json_encode($result);
	}
	
	/**
	 * http://74.91.31.234/topnews/topnews/GetChannelSections.html?cid=UC_x5XG1OV2P6uZZ5FSM9Ttw
	 * 数据好像 没什么用
	 */
	function actionGetChannelSections() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => ''
		);
		$channelId = $_GET['cid'];
		$arr = Youtube::getInstance ()->getChannelSections ($channelId);
		$result ['data'] = $arr;
		echo json_encode($result);
	}
	
	/**
	 * http://74.91.31.234/topnews/topnews/GetPlayLists.html?cid=UC_x5XG1OV2P6uZZ5FSM9Ttw
	 *
	 */     
	function actionGetPlayLists() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => ''
		);
		$channelId = $_GET['cid'];
		$arr = Youtube::getInstance ()->getPlayLists ($channelId);
		$result ['data'] = $arr;
		echo json_encode($result);
	}

	/**
	 * http://74.91.31.234/topnews/topnews/GetVideoCateogriesList.html
	 *
	 */
	function actionGetVideoCateogriesList() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => ''
		);
		$region = $_GET['region'];
		$arr = Youtube::getInstance ()->getVideoCatoriesList ($region);
		$result ['data'] = $arr;
		echo json_encode($result);
	}
	
	// http://74.91.31.234/topnews/topnews/GetLanguages.html
	function actionGetLanguages() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => ''
		);
	
		$region = $_GET['region'];
		$arr = Youtube::getInstance ()->getLanguages ();
		$result ['data'] = $arr;
		echo json_encode($result);
	}
	
	// getRegion
	function actionGetRegion() {
		$result = array (
				'status' => 0,
				'msg' => '',
				'data' => '' 
		);
		
		Utils::getCity ();
		// $result ['data'] = $arr;
		
		// echo json_encode ( $result );
		// var_dump($boardList);
	}
}